/*********************************************************************************
 *      Copyright:  (C) 2025 iot25<lingyun@email.com>
 *                  All rights reserved.
 *
 *       Filename:  send_data_to_server.c
 *    Description:  This file send data to server
 *                 
 *        Version:  1.0.0(02/05/25)
 *         Author:  iot25 <lingyun@email.com>
 *      ChangeLog:  1, Release initial version on "02/05/25 11:47:37"
 *                 
 ********************************************************************************/
#include<stdio.h>
#include<string.h>
#include<errno.h>
#include<unistd.h>
#include"send_data_to_server.h"
#include"logger.h"

int send_data_to_server(int client_fd, char *buffer)
{
	ssize_t				rv;

	if( !client_fd || NULL == buffer ) 
	{
		log_error("invalid_argument!\n");
		return -1;
	}
	rv = write(client_fd, buffer, strlen(buffer));
	if(rv<0)
	{
		log_error("Write to server failure :%s\n", strerror(errno));
		return -1;
	}
	log_debug("Write to server successfully!\n");
	return 0;
}

